<?php

header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');

//index db
require_once '../../index.php';
require_once '../../utils.php';
require_once 'functional.php';

//init properties
$params = array();
$post_arr = array();

//receive properties
$params['identify'] = $_GET['identify'];
$params['hash'] = $_GET['hash'];
$params['id'] = $_GET['id'];

//identify process
if (!identify($db, 'users', $params)) {
  echo json_encode(array('error' => 'No identify.'), JSON_PRETTY_PRINT);
  return;
}

//read single user
$result = read_single($db, 'users', $params);

//get the information
$post_arr = array(
  'id' => $result['id'],
  'rol' => $result['rol'],
  'name' => $result['name'],
  'password' => $result['password'],
  'softDelete' => $result['softDelete'],
  'createdAt' => $result['createdAt']
);

if($post_arr) {
  echo json_encode($post_arr, JSON_PRETTY_PRINT);
  return;
}

echo json_encode(array('error' => 'No post found.'), JSON_PRETTY_PRINT);

?>